
import ocsf.client.*;
import client.ChatClient;
import common.*;
import java.io.*;

/**
 * This class is the login controller
 * @author G_14
 * @version December 2011
 */
public class Login implements Serializable
{
//Instance variables *************************************************  
/**
* Variables that will get the input from the GUI
*/
	private String LoginUser;
	private String LogInpass;
	private int userType;
/**
* The state of the user that the database indicates
*/
	private int state;

//Constructors ****************************************************
/**
* Constructs an instance of the login controller.
*/	
	public Login(int num){
		userType = num;
	}
	
//Instance methods ************************************************
	  
/**
* This method handles the message received from the GUI and send it to the server.
*
* @param u- the user instance received from the GUI.
* @return the answer from the server back to the GUI.
*/		
	public Object checkvalid(User u)
	{	
		this.LogInpass=u.getPassword();
		this.LoginUser=u.getUser();
		SQL s = new SQL(this,userType);
		s.accept();
		return (s.getMsg());
	}
	

	/**
	* @return this method returns the user username received from the GUI
	*/		
	
	public String getUserlogin()
	{
		return(this.LoginUser);
	}
	
	/**
	* @return this method returns the user password received from the GUI
	*/		
		
	public String getPasswordlogin()
	{
		return(this.LogInpass);
	}
	
	/**
	* @return this method returns the state of the user 
	*/			
	public int getState()
	{
		return (this.state);
	}
	
	/**
	 * @return the userType
	 */
	public int getUserType() {
		return userType;
	}

	/**
	 * @param userType the userType to set
	 */
	public void setUserType(int userType) {
		this.userType = userType;
	}

	/**
	*This method set state with the database response
	*@param a-the state number 
	*/	
	public void setState (int a)
	{
		this.state=a;
	}
}